using System;
using System.Globalization;
using System.Windows.Data;
using Prism.Commands;
using System.Reflection;

namespace Tryit.Converters
{
    public class BooleanToCommandConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is bool boolValue && parameter is string param)
            {
                var parts = param.Split('|');
                if (parts.Length == 2)
                {
                    var commandName = boolValue ? parts[0] : parts[1];
                    var dataContext = value.GetType().GetProperty("DataContext")?.GetValue(value);
                    if (dataContext != null)
                    {
                        var commandProperty = dataContext.GetType().GetProperty(commandName);
                        if (commandProperty != null)
                        {
                            return commandProperty.GetValue(dataContext);
                        }
                    }
                }
            }
            return null;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
} 